< previous page page_157 next page >

Page 157
You should also be careful to not use the same name when you declare two separate public variables. If one variable is local in a procedure and the other is public, the local variable will hide the scope of the public one. When the local variable is no longer accessible, the application will then use the public one. The problem here is that you probably won't realize there are two variables with the same name, and you'll use them both as if they were one variable. Of course, the results will be anything but expected.
Passing Information
Okay, now you know that working with local variables is safer than working with global or public variables. Given this fact, and that local variables can be used only by the procedure in which they were declared, what happens when you have multiple procedures that must work with the same data? Just because the procedures are separate doesn't mean they must work with separate data.
If one procedure calculates an array that is printed by another procedure later in the application but the array is local to the first routine, the second one would not be able to access it. No routine can use another routine's local data until you set up some type of sharing mechanism between them. When passing data between two routines, one routine (the calling procedure) passes data to the second routine (the receiving procedure). If the receiving routine modifies or calculates a value that the calling routine needs, the receiving routine can then return that value to the calling routine.
When passing a local variable from one routine to another, you are really passing an argument from the calling routine to the receiving one. Of course, you can pass more than one argument or variable at a time from the calling routine. The receiving routine is said to receive a parameter or variable from the calling routine. Whether you call these passed variables arguments or parameters, the important thing is that you are sending local variables from one routine to another.
Note
You might not realize it, but you already know how to pass arguments to a routine. Every time you use the
MSGBOX function you are passing data. All of the information inside the parentheses are passed as arguments. The MSGBOX function will receive these values and display them.

The parentheses hold the names of the variables that you are passing or the variables that are being received. To pass a local variable from one routine to another, you would place the local variable in parentheses in both the calling and receiving routines as shown in the following:

 
< previous page page_157 next page >

If you like this book, buy it!